import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m=scanner.nextInt();
        int n=scanner.nextInt();
        String ret=new String("");
        String t="0123456789abcdef";
        while(m>0) {
            ret=ret.concat(Character.toString(t.charAt(m%n)));
            m/=n;
        }
        for(int i=ret.length()-1;i>=0;i--) {
            System.out.print(ret.charAt(i));
        }
    }
}
